package com.gjy.concurrency.use;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Random;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-13 14:54:44
 */
public class RandomTest {

    private static final Logger logger = LoggerFactory.getLogger(RandomTest.class);

    @Test
    public void test1() {
        Random random = new Random();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < 10000; i++) {
            int nextInt = random.nextInt(5);
            if (!map.containsKey(nextInt)) {
                map.put(nextInt, 1);
            } else {
                Integer integer = map.get(nextInt);
                map.put(nextInt, ++integer);
            }
        }

        map.forEach((k, v) -> logger.info("{}: {}", k, v));
    }
}
